package com.example.dailyrecord.controller;

import com.example.dailyrecord.base.controller.BaseController;
import com.example.dailyrecord.base.entity.ResultMsg;
import com.example.dailyrecord.entity.StatusCode;
import com.example.dailyrecord.entity.User;
import com.example.dailyrecord.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
@Api(tags = {"用户"})
public class UserController extends BaseController<User> {
    @Resource
    UserService userService;

    @GetMapping("/login")
    @ApiOperation("登录")
    public ResultMsg login(HttpServletRequest request, HttpServletResponse response) {
        return userService.login(request, response);
    }

    @PostMapping("/updatePass")
    @ApiOperation("修改密码")
    public ResultMsg updatePass(HttpServletRequest request, HttpServletResponse response) {
        StatusCode result = userService.updatePass(request, response);
        return ResultMsg.getInstance(result);
    }

    @PutMapping("/register")
    @ApiOperation("注册")
    public ResultMsg register(HttpServletRequest request, HttpServletResponse response) {
        StatusCode result = userService.register(request, response);
        return ResultMsg.getInstance(result);
    }

    @GetMapping("/clearCwcs")
    @Scheduled(cron = "0 * * * * ?")
    @ApiOperation("清除错误次数")
    public void clearCwcs() {
        userService.clearCwcs();
    }

}
